#include <sys/epoll.h>

#include "QF_epoll_event.h"

#define MAX_EPOLL_SIZE 10240

qf_epoll_base::qf_epoll_base ()
{
	epfd = epoll_create (MAX_EPOLL_SIZE);
	if (epfd == -1) {
		/* TODO logging.  */
	}
}

qf_epoll_base::~qf_epoll_base ()
{
	close (epfd);
	release_time_queue ();
}

qf_epoll_base::release_time_queue ()
{
	qf_event_p deal;

	while (!timequeue.empty ()) {
		deal = timequeue.top ();
		timequeue.pop ();
		delete deal;
	}
}

qf_event_p qf_epoll_base::event_new (int fd,
									 short flags,
									 void (*cb)(int, short, void *))
{
	qf_event_p ev = new qf_event_s (fd, flags, cb);
	
	events.push_back (ev);
	return ev;
}

EVerr qf_epoll_base::event_del (qf_event_p ev)
{
	epoll_del ()
	active.remove (ev);
	events.remove (ev);
	time_queue.remove (ev);
	delete ev;
	return EVSuccess; 
}

EVerr event_add (qf_event_p ev, long msec)
{
	
}
